/*    */ package cn.zzuisa.news.filter;
/*    */ 
/*    */ import cn.zzuisa.news.enums.FilterEnums;
/*    */ import cn.zzuisa.news.util.JsonUtil;
/*    */ import cn.zzuisa.news.util.ResultVOUtil;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.Filter;
/*    */ import javax.servlet.FilterChain;
/*    */ import javax.servlet.FilterConfig;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class LoginFilter
/*    */   implements Filter
/*    */ {
/*    */   public void destroy() {}
/*    */   
/*    */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
/* 38 */     HttpServletRequest req = (HttpServletRequest)request;
/* 39 */     HttpServletResponse resp = (HttpServletResponse)response;
/* 40 */     System.out.println("拦截器开始工作---:" + req.getSession().getAttribute("user"));
/* 41 */     if (req.getSession().getAttribute("user") == null) {
/* 42 */       String XRequested = req.getHeader("X-Requested-With");
/*    */       
/* 44 */       if ("XMLHttpRequest".equals(XRequested)) {
/* 45 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(FilterEnums.FILTER_MSG)));
/*    */       } else {
/* 47 */         System.out.println("拦截:" + req.getSession().getAttribute("user"));
/* 48 */         req.getRequestDispatcher("WEB-INF/ftl/user/login.ftl").forward(req, resp);
/*    */       } 
/*    */       return;
/*    */     } 
/* 52 */     System.out.println("放行:" + req.getSession().getAttribute("user"));
/* 53 */     filterChain.doFilter(request, response);
/*    */   }
/*    */   
/*    */   public void init(FilterConfig arg0) throws ServletException {}
/*    */ }


/* Location:              /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/filter/LoginFilter.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */